package spherical_tessellation_test;

import java.util.ArrayList;

import javax.vecmath.Point3f;

public class PlanetGeometry {

	private Point3f center;

	private ArrayList<SurfaceTriangle> baseTriangles;
	private ArrayList<SurfaceTriangle> triangleList;

	public PlanetGeometry() {
		this.baseTriangles = new ArrayList<SurfaceTriangle>();
		this.triangleList = new ArrayList<SurfaceTriangle>();
		
		this.center = new Point3f(0.0f, 0.0f, -5.0f);
		
		this.setupBaseTriangles();
	}

	private void setupBaseTriangles() {
		// Setup starting points
		CoordinateVector point0 = new CoordinateVector(0.0f, 0.0f, 0.2f, this);
		CoordinateVector point1 = new CoordinateVector(0.2f, 0.0f, 0.0f, this);
		CoordinateVector point2 = new CoordinateVector(0.0f, 0.2f, 0.0f, this);
		CoordinateVector point3 = new CoordinateVector(-0.2f, 0.0f, 0.0f, this);
		CoordinateVector point4 = new CoordinateVector(0.0f, -0.2f, 0.0f, this);
		CoordinateVector point5 = new CoordinateVector(0.0f, 0.0f, -0.2f, this);
		// Setup starting triangles
		this.baseTriangles.add(new SurfaceTriangle(point1, point5, point2, 0));
		this.baseTriangles.add(new SurfaceTriangle(point2, point5, point3, 0));
		this.baseTriangles.add(new SurfaceTriangle(point3, point5, point4, 0));
		this.baseTriangles.add(new SurfaceTriangle(point4, point5, point1, 0));
		this.baseTriangles.add(new SurfaceTriangle(point1, point0, point4, 0));
		this.baseTriangles.add(new SurfaceTriangle(point4, point0, point3, 0));
		this.baseTriangles.add(new SurfaceTriangle(point3, point0, point2, 0));
		this.baseTriangles.add(new SurfaceTriangle(point2, point0, point1, 0));
	}

	public Point3f getCenter() {
		return center;
	}

	public void updateTriangleList() {
		for (SurfaceTriangle t : baseTriangles) {
			t.updateTriangleList(triangleList);
		}
	}

	public ArrayList<SurfaceTriangle> getTriangles() {
		return triangleList;
	}

}
